package com.act.web;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.act.domain.PerformanceEvaluation;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.IPerformanceEvaluationService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;

@RestController
@RequestMapping("/pe")
public class PerformanceEvaluationController {
	
	@Resource
	private IPerformanceEvaluationService performanceEvaluationService;

	private final Logger LOGGER = Logger.getLogger(PerformanceEvaluationController.class);	


    @RequestMapping(value="/get/{id}",method=RequestMethod.GET)
    @ResponseBody
    public Response getById(@PathVariable int id){
		try {
			PerformanceEvaluation performanceEvaluation=performanceEvaluationService.getById(id);
			return Response.success(performanceEvaluation);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
    }
    
    @RequestMapping(value="/get",method=RequestMethod.POST)
    @ResponseBody
    public Response  getAll(@RequestBody PagerDTO pagerDTO){
  		try {
  			PagerVo<Map> list=performanceEvaluationService.getAll(pagerDTO);

  			return Response.success(list);
  		} catch (Exception e) {
  			LoggerUtil.error(LOGGER, e);
  		}
  		return Response.fail();
    }
	
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(PerformanceEvaluation performanceEvaluation) {
    	 try {
    		 performanceEvaluationService.add(performanceEvaluation);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
    }
    
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Response update(PerformanceEvaluation performanceEvaluation) {
    	 try {
    		 performanceEvaluationService.update(performanceEvaluation);
             return Response.success();
         } catch (Exception e) {
           
             return Response.fail();
         }
	
    }
    
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response delete(@PathVariable int id) {
    	 try {
    		 performanceEvaluationService.delete(id);
             return Response.success();
         } catch (Exception e) {
             return Response.fail();
         }
    }
    
    @RequestMapping(value="/getByJobnumOrState/{jobnum}/{deal_status}",method=RequestMethod.POST)
    @ResponseBody
    public Response getByJobnumOrState(@PathVariable int deal_status,@PathVariable String jobnum,@RequestBody PagerDTO pagerDTO){
		try {
			PagerVo<Map> amlist=performanceEvaluationService.getByJobnumOrState(deal_status, jobnum, pagerDTO);
			return Response.success(amlist);
		} catch (Exception e) {
			LoggerUtil.error(LOGGER, e);
		}
		return Response.fail();
    }
}
